/*
 * Copyright 1999-2017 Alibaba Group Holding Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
// package com.alibaba.druid.sql.dialect.mysql.ast;

// import com.alibaba.druid.DbType;
// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.ast.SQLIndex;
// import com.alibaba.druid.sql.ast.statement.SQLTableConstraint;
// import com.alibaba.druid.sql.ast.statement.SQLUnique;
// import com.alibaba.druid.sql.ast.statement.SQLUniqueConstraint;
// import com.alibaba.druid.sql.dialect.ads.visitor.AdsVisitor;
// import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

#include "MySqlKey.h"
#include "../../../visitor/SQLASTVisitor.h"
#include "../visitor/MySqlASTVisitor.h"
#include "../../ads/visitor/AdsVisitor.h"
#include "../../../../utils/instanceof.h"
#include "../../../../utils/listTran.h"
#include "../../../ast/statement/SQLSelectOrderByItem.h"

MySqlKey::MySqlKey()
{
  dbType = DbType_ptr(new DbType(&DbType::mysql));
}

void MySqlKey::accept0(SQLASTVisitor_ptr visitor)
{
  if (instanceof <SQLASTVisitor, MySqlASTVisitor>(visitor.get()))
  {
    std::shared_ptr<MySqlASTVisitor > tmp = std::dynamic_pointer_cast<MySqlASTVisitor>(visitor);
    accept0(tmp);
  }
  else if (instanceof <SQLASTVisitor, AdsVisitor>(visitor.get()))
  {
    std::shared_ptr<AdsVisitor > tmp = std::dynamic_pointer_cast<AdsVisitor>(visitor);
    accept0(tmp);
  }
}

void MySqlKey::accept0(std::shared_ptr<AdsVisitor > visitor)
{
  if (visitor->visit(SharedObject(MySqlKey)))
  {
    acceptChild(visitor, SQLUnique::getName());
    SQLObject_list_ptr  tmp = ListTran::tran_class<SQLSelectOrderByItem, SQLObject>(SQLUnique::getColumns());
    acceptChild(visitor, tmp);
    acceptChild(visitor, SQLUnique::getName());
  }
  visitor->endVisit(SharedObject(MySqlKey));
}

void MySqlKey::accept0(std::shared_ptr<MySqlASTVisitor > visitor)
{
  if (visitor->visit(SharedObject(MySqlKey)))
  {
    acceptChild(visitor, SQLUnique::getName());
    SQLObject_list_ptr  tmp = ListTran::tran_class<SQLSelectOrderByItem, SQLObject>(SQLUnique::getColumns());
    acceptChild(visitor, tmp);
    acceptChild(visitor, SQLUnique::getName());
  }
  visitor->endVisit(SharedObject(MySqlKey));
}

string_ptr  MySqlKey::getIndexType()
{
  return indexDefinition->getOptions()->getIndexType();
}

void MySqlKey::setIndexType(string_ptr  indexType)
{
  indexDefinition->getOptions()->setIndexType(indexType);
}

BOOL_ptr MySqlKey::isHasConstraint()
{
  return indexDefinition->getHasConstraint();
}

void MySqlKey::setHasConstraint(BOOL_ptr hasConstraint)
{
  indexDefinition->setHasConstraint(hasConstraint);
}

void MySqlKey::cloneTo(MySqlKey_ptr x)
{
  SQLUnique::cloneTo(x);
}

SQLObject_ptr MySqlKey::clone()
{
    SQLObject_ptr clone_tmp = MySqlKey_ptr(new MySqlKey());
    MySqlKey_ptr x = std::dynamic_pointer_cast<MySqlKey>(clone_tmp);
  // MySqlKey *x;
  cloneTo(x);
  return x;
}

SQLExpr_ptr MySqlKey::getKeyBlockSize()
{
  return indexDefinition->getOptions()->getKeyBlockSize();
}

void MySqlKey::setKeyBlockSize(SQLExpr_ptr x)
{
  indexDefinition->getOptions()->setKeyBlockSize(x);
}
